<template>
    <div class="top">
        <!-- 内容区 -->
        <div class="contain">
            <div class="left" @click="goHome">
                <img src="../../assets//images/logo.png" alt="">
                <p>品牌通 卖号第一快</p>
            </div>
            <div class="right">
                <p class="help">帮助中心</p>
                <p class="login" @click="login" v-if="!userStore.UserInfo.name">登录/注册</p>
                <!-- //如果存在用户消息就显示 -->
                <el-dropdown v-if="userStore.UserInfo.name">
                    <span class="el-dropdown-link">
                        {{ userStore.UserInfo.name }}
                        <el-icon class="el-icon--right">
                            <arrow-down />
                        </el-icon>
                    </span>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item @click="goUser">实名认证</el-dropdown-item>
                            <el-dropdown-item>挂号订单</el-dropdown-item>
                            <el-dropdown-item>就诊人管理</el-dropdown-item>
                            <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
            </div>
        </div>
    </div>
</template>
<script setup lang="ts">
//引入小仓库
import useUserStore from '@/store/user';
import { useRouter } from 'vue-router';
import { ArrowDown } from '@element-plus/icons-vue'
//使用仓库组件
let userStore = useUserStore();
let $router = useRouter();
const goHome = () => {
    $router.push({ path: '/' })
}
const goUser = () => {
    $router.push({ path: '/user/menber' })
}
//控制登录组件显示
let login = () => {
    userStore.visable = true
}
//退出登录按钮回调
const logout = () => {
    //通知pinia仓库清除用户信息
    userStore.logout();
    $router.push({ path: '/home' })
}
</script>
<style lang="scss" scoped>
.top {
    width: 100%;
    height: 80px;
    background-color: white;
    display: flex;
    justify-content: center;

    .contain {
        width: 1200px;
        height: 70px;
        justify-content: space-between;
        display: flex;

        .left {
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 20PX;
            color: skyblue;

            img {
                width: 70px;
                height: 70px;
                margin-right: 20px;
            }

        }

        .right {
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 14px;
            color: gray;

            .login {
                margin-left: 10px;

            }

        }
    }

    .help {
        margin-right: 10px
    }

}
</style>